classdef TaskInfo
    %UNTITLED Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
        Taskname = '';
        Dependancy = '';
    end
    
    properties (SetAccess = private)
        LastCompletedDate = [];
    end
    
    methods
        
        function t = TaskInfo(taskname, dependancy)
            if nargin > 0
                t.Taskname = taskname;
                if nargin > 1
                    t.Dependancy = dependancy;
                end
            end
        end
        
        function obj = set.Taskname(obj,taskname)
            if ~(ischar(taskname))
                error('Taskname must be a string')
            end
            obj.Taskname = taskname;
        end % Taskname set function
        
        function obj = set.Dependancy(obj,taskname)
            if ~(ischar(taskname))
                error('Dependancy taskname must be a string')
            end
            obj.Dependancy = taskname;
        end % Dependancy set function
        
        function obj = SetComplete(obj)
            obj.LastCompletedDate = datevec(now);
        end
        
        function obj = SetToDo(obj)
            obj.LastCompletedDate = [];
        end
        
        function td = IsToDo(obj)
            td = isempty(obj.LastCompletedDate);
        end
        
        function td = IsDone(obj)
            td = ~isempty(obj.LastCompletedDate);
        end
        
        function td = HasDependancy(obj)
            td = ~isempty(obj.Dependancy);
        end
        
    end
    
    methods(Static)
        
        function index = FindTask(subjectInfo, taskname)
            index = find(strcmp(taskname, ...
                {subjectInfo.Tasks(:).Taskname}));
        end
        
    end
    
    methods(Static) 
        
        function dispHeader()
            fprintf(1,'                      Taskname |                Dependancy |           Completed\n');
            fprintf(1,'   ----------------------------|---------------------------|---------------------\n');
        end
        
        function dispRow(obj)
            if length(obj.Taskname)>25
                t = obj.Taskname(length(obj.Taskname)-24:length(obj.Taskname));
                t(1:2) = '.';
            else
                t = obj.Taskname;
            end
            if length(obj.Dependancy)>25
                d = obj.Dependancy(length(obj.Dependancy)-24:length(obj.Dependancy));
                d(1:2) = '.';
            else
                d = obj.Dependancy;
            end
            fprintf(1,'     %25s | %25s | %s\n', t, d, datestr(obj.LastCompletedDate, 'dd-mm-yyyy HH:MM:ss'));
            
        end
        
        function dispFooter()
            fprintf(1,'   ------------------------------------------------------------------------------\n');
        end
   
    end
end

